
<html><head></head><body>
<?php
$con = mysql_connect("localhost","root","");
if(!$con){die('Connection Error!:' . mysql_error());}
        mysql_select_db ("usabilityevaluation",$con);
        
        
         $Participant=$_POST['Participant'];//get participant number
              echo "<p>Participant number ".$Participant."</p>";
              
         echo"<form method='post' action='SaveExp.php'>";
         $Title = $_POST['Title'];
         
         //retreive id Ecperiment 
         $query0 = "SELECT id_exp FROM experimentation WHERE Title='$Title'";
        $result = mysql_query($query0) or die('Error, retrieve query failed Exp');
        $Exp_id = mysql_result($result, 0);

$query111="SELECT count(id_task) FROM task WHERE id_experiment=$Exp_id";
  $result111 =mysql_query($query111) or die('Error, retrieve query failed Question');
  while($row111 = mysql_fetch_array($result111)){$counter=$row111[0];}
for ($i=1;$i<=$counter;$i++){//Task Loop
echo"<form name='form'".$i."action='SaveExp.php' method='post'>";
echo "<tr><td>Task ID</td><td><input type='text' value='".$i."' disabled='false'/></td></tr>
<table border='1'>
    <tr>
    <th>Question ID</th>
    <th>Title</th>
    <th>Answer</th><th>Comment</th><td><input type='submit' name='t".$i."' value='delete Task'/></td>
    </tr>" ;
for($y=1;$y<=5;$y++){//Question Loop
$query2= "Select * from question where id_task='$i' and n_question=$y  and id_exp='$Exp_id'"; //this is the right line
//$query2= "Select * FROM question WHERE id_question='$y'and id_task='$i' and id_exp=67";
  $result2 =mysql_query($query2) or die('Error, retrieve query failed Question');
    
  $query3= "Select a.title from answers as a ,question as q where q.n_question=$y and q.id_exp=$Exp_id and a.id_question=q.id_question";
 // $query3= "Select * from answers Where id_question=$y and id_exp=$Exp_id";
  // $query3= "Select * from answers where id_question='$y' and id_task='$i' and id_exp=67";
      $result3 =mysql_query($query3) or die('Error, retreive Answer query failed');

     $cntr=1;// this counter to make the Radio button same name
while($row2 = mysql_fetch_array($result2))
  {//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
   echo "<tr>";
   $Type=$row2['Type'];
     echo "<td>" . $row2['n_question'] . "</td>";
     echo "<td>" . $row2['Title'] . "</td><td> ";

     //Start Add Answer CheckBoxes
     if ($Type=='Mutiple Choice'){
   while($row3 = mysql_fetch_array($result3)){
 echo  $row3[0] . "<input type='checkbox' name='".$row3[0]."' value='".$row3[0]."' />";
}
}
else if ($Type=='TrueFalse'){
 while($row3 = mysql_fetch_array($result3)){
 echo  $row3[0] . "<input type='radio' name='$cntr' value='".$row3[0]."' />";
}
}
else {
 while($row3 = mysql_fetch_array($result3)){
 echo  $row3[0] . "<textarea  type='text' name='".$row3[0]."' ></textarea >";
}
}

echo "</td>";
//finish ADD Answer
  echo "<td><textarea  value=".$row2['Comment']." ></textarea></td>";
   echo "<td><input type='submit' name='".$y."' value='delete Question' style='visibility:hidden;'/><td>Add Question<a href='questionSave.php'><img id='image1' src='images/Add.png' /></a></td></tr>";
  echo "</tr>";
  
  }
       $cntr++;
}
echo "</table><br/>";
} 
mysql_close($con);
?>
</body>
</html>